#ifndef TCPSERVER_H
#define TCPSERVER_H

#include <QTcpServer>
#include <QList>
#include "ClientSocket.h"



/*
    TcpServer server;
    connect(&server,&TcpServer::connected,this,&Server::onConnected);
    connect(&server,&TcpServer::disconnected,this,&Server::onDisconnected);
    connect(&server,&TcpServer::readyRead,this,&Server::onReadyRead);

    server.listen(QHostAddress::Any,723);


    server.Remove(sock);

*/




//template<class _TcpSocket_>
class TcpServer : public QTcpServer
{
    Q_OBJECT
public:
    TcpServer(QObject * parent = 0);
    ~TcpServer();

protected:

    //如果要使用派生ClientSocket时,必须重载
    virtual TcpSocket* createTcpSocket();

    //连接客户端方法2:手动创建QTcpSocket
    //virtual void incomingConnection(int socketId)
    virtual void incomingConnection(qintptr handle);

signals:
//以下分别是TcpSocket发出的信号,Server作为中间人
    void hostFound(TcpSocket *);
    void connected(TcpSocket *);
    void disconnected(TcpSocket *);
    void stateChanged(qint16 state,TcpSocket *);
    void error(qint16,TcpSocket *);

    void readyRead(TcpSocket *);
    void bytesWritten(qint64 bytes,TcpSocket *);
    void aboutToClose(TcpSocket *);
    void readChannelFinished(TcpSocket *);

public slots:
    void Remove(TcpSocket* pTcpSocket);

public:
    QList<TcpSocket*> clientList;
};


#endif // TCPSERVER_H
